using System.Data.Common;

namespace Dapper.Extensions.Hooks
{
	internal class WrappedConnectionFactory<T>(Func<DbConnection> factory, Func<Task<DbConnection>> asyncFactory)
		: IHookedDbConnectionFactory<T>
	{
		public DbConnection CreateConnection(ISqlHooks<T> hooks, T context) => 
			new WrappedConnection<T>(factory(), hooks, context);

		public async Task<DbConnection> CreateConnectionAsync(ISqlHooks<T> hooks, T context)
		{
				var connection = await asyncFactory();
				return new WrappedConnection<T>(connection, hooks, context); 
		}
	}
}
